//aes加密
function jsencrypt(data) {

    var keycode = $("#keycode").val();

    var key  = CryptoJS.enc.Latin1.parse(keycode);
    var iv   = CryptoJS.enc.Latin1.parse(keycode);

    var encrypted = CryptoJS.AES.encrypt(data, key, {iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding}).toString();

    $("input[name='password']").val(encrypted);
}

function getResponse(e) {
    LSM.captchaSuccess(e)
}
function getRegResponse(e) {
    e && $(".l-captcha").parent().find(".error").remove()
}
var LSM = LSM || {};
!
    function(e) {
        "function" == typeof define && define.amd ? define(["jquery"], e) : e(jQuery)
    }(function(e) {
        function t(e) {
            return e
        }
        function n(e) {
            return decodeURIComponent(e.replace(r, " "))
        }
        function i(e) {
            0 === e.indexOf('"') && (e = e.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\"));
            try {
                return o.json ? JSON.parse(e) : e
            } catch (e) {}
        }
        var r = /\+/g,
            o = e.cookie = function(r, s, a) {
                if (void 0 !== s) {
                    if ("number" == typeof(a = e.extend({}, o.defaults, a)).expires) {
                        var c = a.expires,
                            l = a.expires = new Date;
                        l.setDate(l.getDate() + c)
                    }
                    return s = o.json ? JSON.stringify(s) : String(s), document.cookie = [o.raw ? r : encodeURIComponent(r), "=", o.raw ? s : encodeURIComponent(s), a.expires ? "; expires=" + a.expires.toUTCString() : "", a.path ? "; path=" + a.path : "", a.domain ? "; domain=" + a.domain : "", a.secure ? "; secure" : ""].join("")
                }
                for (var u = o.raw ? t : n, d = document.cookie.split("; "), f = r ? void 0 : {}, m = 0, h = d.length; m < h; m++) {
                    var p = d[m].split("="),
                        v = u(p.shift()),
                        g = u(p.join("="));
                    if (r && r === v) {
                        f = i(g);
                        break
                    }
                    r || (f[v] = i(g))
                }
                return f
            };
        o.defaults = {}, e.removeCookie = function(t, n) {
            return void 0 !== e.cookie(t) && (e.cookie(t, "", e.extend({}, n, {
                    expires: -1
                })), !0)
        }
    }), function(e) {
    var t = [],
        n = 0,
        i = {
            usernameNeed: '5-25个字符(中文2个字符),支持中英文、数字、"_"，以中英文开头',
            usernameRange: "用户名的长度请控制在5-25个字符",
            usernameError: "不可包含标点等特殊字符，仅支持中文、英文、数字、下划线",
            usernameFirst: "用户名不可以为数字打头",
            usernameBlank: "请输入用户名",
            usernameDismiss: "很遗憾，用户名已存在",
            passwordNeed: "6-16个字符，不可为纯数字",
            passwordRange: "密码的长度请控制在6-16个字符",
            passwordError: "为了您的密码安全，不能为纯数字",
            passwordBlank: "请输入密码",
            confirmpasswordNeed: "请再次输入密码",
            confirmpasswordError: "两次密码输入不一致",
            confirmpasswordBlank: "请再次输入密码",
            emailNeed: "请输入邮箱用以激活账号",
            emailError: "邮箱格式错误",
            emailBlank: "请输入邮箱",
            mobileNeed: "请输入手机号码，格式为：13712345678",
            mobileError: "手机格式错误",
            mobileBlank: "请输入手机号码"
        },
        r = {
            username: i.usernameNeed,
            password: i.passwordNeed,
            confirmpassword: i.confirmpasswordNeed,
            email: i.emailNeed,
            mobile: i.mobileNeed
        },
        o = {
            success: e('<span class="success"></span>'),
            tip: e('<span class="tip"></span>'),
            error: e('<span class="error"></span>')
        },
        s = function(e, t) {
            return l(e), u(e), c(e), e.closest(".control-group").addClass("warning"), o.error.clone().html(t).appendTo(e.parent())
        },
        a = function(t) {
            if (c(t), l(t), u(t), !(e(this).parent().find(".success").length > 0)){
                //return o.success.clone().appendTo(t.parent())
            }
        },
        c = function(e) {
            return e.closest(".control-group").removeClass("warning"), e.parent().find(".error").remove()
        },
        l = function(e) {
            return e.closest(".control-group").removeClass("warning"), e.parent().find(".tip").remove()
        },
        u = function(e) {
            return e.closest(".control-group").removeClass("warning"), e.parent().find(".success").remove()
        },
        d = function(t) {
            var n = t.attr("data-validate");
            if (!(e(this).parent().find(".tip").length > 0)) return o.tip.clone().html(r[n]).appendTo(t.parent())
        },
        f = function(t) {
            return 0 == e.trim(t).length
        },
        m = function(e) {
            for (var t = e.length, n = 0, i = 0; i < t; i++) e.charCodeAt(i) < 27 || e.charCodeAt(i) > 126 ? n += 2 : n++;
            return n
        },
        h = {
            username: function(e, t) {
                return f(e) ? (s(t, i.usernameBlank), !1) : (t.val(e.toLowerCase()), m(e) < 5 || m(e) > 25 ? (s(t, i.usernameRange), !1) : /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/.test(e) ? !/^([\d])/.test(e) || (s(t, i.usernameFirst), !1) : (s(t, i.usernameError), !1))
            },
            password: function(t, n) {
                if (f(t)) return s(n, i.passwordBlank), !1;
                if (t.length < 6 || t.length > 16) return s(n, i.passwordRange), !1;
                if (/^\d+$/.test(t)) return s(n, i.passwordError), !1;
                var r = n.attr("data-equal"),
                    o = e("#" + r);
                return o.val() == t && (c(o), a(o)), !0
            },
            confirmpassword: function(t, n) {
                if (f(t)) return s(n, i.confirmpasswordBlank), !1;
                var r = n.attr("data-equal"),
                    o = e("#" + r);
                return o.val() !== t ? (s(n, i.confirmpasswordError), !1) : 0 != o.parent().find(".success").length || (s(n, ""), !1)
            },
            email: function(e, t) {
                return f(e) ? (s(t, i.emailBlank), !1) : !! /^(?:[a-z0-9]+[_\-+.]?)*[a-z0-9]+@(?:([a-z0-9]+-?)*[a-z0-9]+.)+([a-z]{2,})+$/i.test(e) || (s(t, i.emailError), !1)
            },
            mobile: function(e, t) {
                return f(e) ? (s(t, i.mobileBlank), !1) : !! /^1[3-9]\d{9}$/.test(e) || (s(t, i.mobileError), !1)
            }
        },
        p = function(t, n) {
            return e(t, n)
        },
        v = function(e) {
            return e.val() || (e.is("[contenteditable]") ? e.text() : "")
        },
        g = function(e) {
            var t = e.attr("data-validate"),
                n = v(e),
                i = h[t](n, e);
            return i && "username" == t ? C.call(this, e, "get", "/Home/Admin/validation", {
                field: "username",
                value: n,
                format: "json"
            }) : i && "email" == t ? C.call(this, e, "get", "/Home/Admin/validation", {
                field: "email",
                value: n,
                format: "json"
            }) : (i && ("mobile" == t && "" == n || a(e)), $.call(this, e, i))
        },
        T = function(n, i) {
            var r;
            e.each(n, function(n, o) {
                e(o).on(i, function() {
                    e(this).each(function() {
                        (r = g.call(this, e(this))) && t.push(r)
                    })
                })
            })
        },
        w = function(n, i) {
            return !(!i || T.length) || (t = e.map(n, function(t) {
                    var n = g.call(null, e(t));
                    if (n) return n
                }), !! T.length && t)
        },
        $ = function(e, t) {
            if (e) {
                v(e);
                return t ? void 0 : e
            }
        },
        C = function(t, n, i, r) {
            var o;
            e.ajax({
                type: n,
                url: i,
                data: r,
                success: function(e) {

                    if(e.error == 0){
                        return (a(t), o = !0), $.call(this, t, o);
                    }else{
                        return (s(t, e.msg), o = !1);
                    }

                    //return 0 !== e.error ? (s(t, e.msg), o = !1) : (a(t), o = !0), $.call(this, t, o)

                },
                error: function() {}
            })
        },
        b = function() {
            return "" != e("#lc-captcha-response").val() || (s(e(".l-captcha"), "请先进行验证"), !1)
        };
    e.fn.lsmRegister = function() {
        var i = this,
            r = r || {},
            o = r.before ||
                function() {
                    return !0
                }, s = r.identifie || "[require]", a = p(s, i), f = r.method || "blur";
        f && T.call(this, a, f), i.on("focus", s, function(t) {
            c.call(this, e(this)), u.call(this, e(this)), l.call(this, e(this)), d.call(this, e(this))
        }), i.on("submit", function(e) {
            return n && e.preventDefault(), o.call(this), w.call(this, a, f), t.length ? (b(), e.preventDefault()) : b() ? void(n = 1) : e.preventDefault();
        });

    }
    e.fn.lsmRegister_rebuild = function() {
        var i = this,
            r = r || {},
            o = r.before ||
                function() {
                    return !0
                }, s = r.identifie || "[require]", a = p(s, i), f = r.method || "blur";
        f && T.call(this, a, f), i.on("focus", s, function(t) {
            c.call(this, e(this)), u.call(this, e(this)), l.call(this, e(this)), d.call(this, e(this))
        }), i.on("submit", function(e) {

             var obj = w.call(this, a, f);

             if(obj.length == 2){
                return e.preventDefault();
             }else{
                return true;
             }
        });
    }
}(jQuery), LSM.login = function() {
    var e = $("#loginForm");
    if (0 == e.length) return 0;
    var t = e.find($(".form-text")),
        n = $('<span class="error"></span>'),
        i = {
            username: "请输入用户名或Email",
            password: "请输入密码",
            captcha: "请先进行验证"
        },
        r = function(e, t) {
            if (!e.parent().find(".error").length) return n.clone().html(t).appendTo(e.parent())
        },
        o = function(e) {
            return $(e.currentTarget).parent().find(".error").remove()
        };
    t.on("blur", function(e) {
        var t = $(e.currentTarget),
            n = $.trim(t.val()),
            s = t.attr("name");
        "" == n ? r(t, i[s]) : o(t)
    }), t.on("focus", o);
    var s = function() {
        var e = $(".l-captcha");
        "" == $("#lc-captcha-response").val() && 0 == e.parent().find(".error").length && n.clone().html(i.captcha).appendTo(e.parent())
    };
    this.captchaSuccess = function(e) {
        e && $(".l-captcha").parent().find(".error").remove()
    }, e.on("submit", function(n) {
        t.each(function() {
            $(this).trigger("blur")
        }), s(), e.find(".error").length > 0 && n.preventDefault()
    });
}, LSM.resendEmail = function() {
    var e = $("#J_resend");

    e.length && (this.resendNow = function(t) {

        if (t.preventDefault(), 1 != e.attr("data-pass")) {
            var n = this;
            e.attr("data-pass", 1), $.ajax({
                type: "GET",
                url: "/Home/Admin/send_mail",
                success: function(t) {
                    0 == t.error ? (n.setNCookieTime(), n.setNBtnTimer(60)) : -2 == t.error ? (alert("时间间隔60秒"), e.attr("data-pass", 0)) : -3 == t.error && (alert("未登录"), e.attr("data-pass", 0))
                }
            })
        }
    }, this.setNBtnTimer = function(t) {
        !
            function n() {
                if (0 == t) return e.html("重新发送"), e.attr("data-pass", 0), void $.cookie("LUOSENDTIME", (new Date).getTime());
                setTimeout(function() {
                    t--, e.html("已发送，" + t + "秒后可重发邮件"), n()
                }, 1e3)
            }()
    }, this.setNCookieTime = function() {
        var e = (new Date).getTime();
        $.cookie("LUOSENDTIME", e)
    }, this.sendNInit = function() {
        var e = $.cookie("LUOSENDTIME");
        if (void 0 === e);
        else {
            var t = (new Date).getTime();
            t - e < 6e4 && this.setNBtnTimer(60 - parseInt((t - e) / 1e3))
        }
    }, this.sendNInit(), e.on("click", $.proxy(this.resendNow, this)))
}, LSM.findPasswordEmail = function() {
    var e = $("#J_find_resend");
    e.length && (this.resendNow = function(t) {
        if (t.preventDefault(), 1 != e.attr("data-pass")) {
            var n = this,
                i = $("#J_email_info").html();
            $.ajax({
                type: "POST",
                url: "/Home/Admin/reset_password",
                data: {
                    email: i
                },
                success: function(e) {
                    0 == e.error ? (n.setCookieTime(), n.setBtnTimer(60)) : -2 == e.error ? alert("时间间隔60秒") : -1 == e.error && alert("email地址错误")
                }
            })
        }
    }, this.setBtnTimer = function(t) {
        e.attr("data-pass", 1), function n() {
            if (0 == t) return e.html("重新发送"), e.attr("data-pass", 0), void $.removeCookie("LUOFINDTIME");
            setTimeout(function() {
                t--, e.html("已发送，" + t + "秒后可重发邮件"), n()
            }, 1e3)
        }()
    }, this.setCookieTime = function() {
        var e = (new Date).getTime();
        $.cookie("LUOFINDTIME", e)
    }, this.sendInit = function() {
        var e = $.cookie("LUOFINDTIME");
        if (void 0 === e);
        else {
            var t = (new Date).getTime();
            t - e < 6e4 && this.setBtnTimer(60 - parseInt((t - e) / 1e3))
        }
    }, this.sendInit(), e.on("click", $.proxy(this.resendNow, this)))
}, LSM.showPower = function() {
    function e(e, t) {
        return Math.floor(Math.random() * (t - e + 1)) + e
    }
    var t = $(".anim-container");
    if (t.length) {
        var n = /Webkit/i.test(navigator.userAgent),
            i = /Chrome/i.test(navigator.userAgent),
            r = !! ("ontouchstart" in window),
            o = /Android/i.test(navigator.userAgent),
            s = document.documentMode;
        if (r && o && !i) console.log("for iOS devices or Android devices running Chrome only");
        else if (!$.cookie("LUOSHOW")) {
            $.cookie("LUOSHOW", "1", {
                expires: 365
            }), t.show(), $("body").addClass("show-power"), $.velocity.defaults.easing = "easeInOutsine";
            for (var a = r ? o ? 40 : 70 : i ? 175 : 125, c = "", l = $("#count"), u = 0; u < a; u++) c += '<div class="dot"></div>';
            $dots = $(c), l.html(a);
            var d = $("#container"),
                f = ($("#browserWidthNotice"), $("#welcome")),
                m = window.screen.availWidth,
                h = window.screen.availHeight,
                p = h - (document.documentElement.clientHeight || h),
                v = {
                    perspective: [215, 50],
                    opacity: [.9, .55]
                };
            s || (v.rotateZ = [5, 0]), f.velocity({
                opacity: [0, .65]
            }, {
                display: "none",
                delay: 3500,
                duration: 1100
            }), d.css("perspective-origin", m / 2 + "px " + (.45 * h - p) + "px").velocity(v, {
                duration: 800,
                loop: 1,
                delay: 3250
            }), n && $dots.css("boxShadow", "0px 0px 4px 0px #4bc2f1"), $dots.velocity({
                translateX: [function() {
                    return "+=" + e(-m / 2.5, m / 2.5)
                }, function() {
                    return e(0, m)
                }],
                translateY: [function() {
                    return "+=" + e(-h / 2.75, h / 2.75)
                }, function() {
                    return e(0, h)
                }],
                translateZ: [function() {
                    return "+=" + e(-725, 600)
                }, function() {
                    return e(-725, 600)
                }],
                opacity: [function() {
                    return Math.random()
                }, function() {
                    return Math.random() + .1
                }]
            }, {
                duration: 6e3
            }).velocity("reverse", {
                easing: "easeOutQuad"
            }).velocity({
                opacity: 0
            }, {
                duration: 2e3,
                complete: function() {
                    f.show().velocity({
                        opacity: 1
                    }, {
                        duration: 3500,
                        display: "block"
                    }), f.find(".btn").show()
                }
            }).appendTo(d), t.on("click", ".btn", function(e) {
                e.preventDefault(), t.fadeOut(), $("body").removeClass("show-power")
            })
        }
    }
}, function() {

    var e = $("#form");

    e.length && e.lsmRegister();

}(), function() {

    var e = $("#rebuild_form");

    e.length && e.lsmRegister_rebuild();

}(), function() {
    var e = $(".client-list");
    e.length && e.find("li").on({
        mouseover: function() {
            $(this).addClass("active")
        },
        mouseout: function() {
            $(this).removeClass("active")
        }
    })
}(), function() {
    var e = $(".dom-content");
    if (!e.length) return 0;
    e.scrollNav({
        sections: ".scroll-nav-title",
        subSections: ".scroll-nav-sub-title",
        headlineText: "快速导航",
        showTopLink: !1
    })
}(), $(function() {
    LSM.resendEmail(), LSM.findPasswordEmail(), LSM.login()
});